<template>
  <div class="goods">
    <div class="image" @click.stop="toDetail">
      <img :src="topic.image" width="140px" height="140px" alt style="border-radius: 10px;" />
    </div>
    <div class="body" @click.stop="toDetail">
      <van-row
        class="goods-user"
        :class="marginbottom"
        type="flex"
        justify="start"
        align="center"
        @click.stop="toUserindex"
      >
        <van-col class="image">
          <van-image :src="user.image" round width="30px" height="30px"></van-image>
        </van-col>
        <van-col>
          <div class="auther">{{user.name}}</div>
          <div class="time">{{time}}</div>
        </van-col>
      </van-row>
      <div
        class="title van-multi-ellipsis--l2"
        ref="goodstitle"
        :class="marginbottom"
      >{{topic.title}}</div>
      <div class="intro" :class="marginbottom">{{"九成新"}}</div>
      <div class="price" :class="marginbottom">￥{{10}}</div>
    </div>
    <van-icon name="ellipsis" size="22px" @click.stop="showOperation" />
    <operation-box class="operation" v-if="operate_show"></operation-box>
  </div>
</template>

<script>
import time from "@/common/time";
import operationbox from "../Popup/topic-operate";
export default {
  name: "good-card",
  props: {
    user: {
      type: Object,
      require: true,
    },
    topic: {
      type: Object,
      require: true,
    },
  },
  data() {
    return {
      textHeight: 0,
      operate_show: false,
    };
  },
  mounted() {
    setTimeout(() => {
      this.textHeight = this.$refs.goodstitle.clientHeight;
    }, 500);
  },
  computed: {
    time() {
      return time.timeshow(this.topic.time);
    },
    marginbottom() {
      if (this.textHeight > 25) {
        return "marginbottom5";
      } else {
        return "marginbottom10";
      }
    },
  },
  methods: {
    toDetail() {
      this.$router.push({ path: "/topic", query: { id: this.topic.id } });
    },
    toUserindex() {
      this.$router.push({
        path: "/account/userindex",
        query: { user: this.user.name },
      });
    },
    showOperation() {
      this.operate_show = true;
    },
  },
  components: {
    "operation-box": operationbox,
  },
};
</script>
<style>
.goods {
  position: relative;
  display: inline-flex;
  background: #fff;
  width: 95%;
  padding: 10px;
  margin-bottom: 10px;
  border-radius: 10px;
  box-shadow: 3px 3px 5px 0px #97979759;
}
.goods .body {
  width: 100%;
  padding-left: 10px;
  text-align: left;
}
.goods-user {
  padding: 10px 10px 5px 10px;
  text-align: left;
}
.goods-user .auther {
  min-width: 200px;
  max-width: 250px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
  color: #404040eb;
}
.goods-user .time {
  font-size: 12px;
  color: #909090;
}
.goods-user .image {
  text-align: center;
  padding-right: 10px;
}
.marginbottom10 {
  margin-bottom: 10px;
}
.marginbottom5 {
  margin-bottom: 5px;
}
.goods .body .intro {
  font-size: 14px;
  color: gray;
}
.goods .body .price {
  color: crimson;
}
.goods .van-icon {
  position: absolute;
  right: 15px;
  top: 10px;
  color: #4994e5;
}
</style>